package com.smy.jkds.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smy.jkds.po.*;
import com.smy.jkds.service.JkdsClockConfigService;
import com.smy.jkds.vo.IdListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 番茄钟配置表 前端控制器
 * </p>
 *
 * @author 01140
 * @since 2021-10-30
 */
@RestController
@RequestMapping("/jkds")
public class JkdsClockConfigController {
    @Autowired
    JkdsClockConfigService jkdsClockConfigService;

    @PostMapping("/createClockConfig")
    public Result createCard(@RequestBody JkdsClockConfig jkdsClockConfig, @CurrentUser JkdsUser user){
//        card.setUserId(user.getUserId());
//        card.setUserName(user.getUserName());
        boolean r = jkdsClockConfigService.save(jkdsClockConfig);
        return r ? Result.success("创建成功") : Result.success("创建失败");
    }

    @PostMapping("/updateClockConfig")
    public Result updateCard(@RequestBody JkdsClockConfig jkdsClockConfig, @CurrentUser JkdsUser user){
        boolean r = jkdsClockConfigService.updateById(jkdsClockConfig);
        return r ? Result.success("更新成功") : Result.success("更新失败");
    }

    @PostMapping("/deleteClockConfig")
    public Result deleteCard(@RequestBody IdListVO cardDeleteVO, @CurrentUser JkdsUser user){
        if (cardDeleteVO == null || cardDeleteVO.getIdList() == null){
            return Result.success("删除成功");
        }
//        QueryWrapper<Card> queryWrapper = new QueryWrapper<>();
//        queryWrapper.in(Card.ColumnEnum.id.name(), cardDeleteVO.getIdList());
        boolean r = jkdsClockConfigService.removeByIds(cardDeleteVO.getIdList());
        return r ? Result.success("删除成功") : Result.success("删除失败");
    }

    @GetMapping("/queryClockConfigList")
    public Result queryTaskList(@CurrentUser JkdsUser loginUser){
        QueryWrapper<JkdsClockConfig> queryWrapper = new QueryWrapper<>();
        return Result.success("查询成功",jkdsClockConfigService.list(queryWrapper));
    }
    @GetMapping("/queryClockConfigById")
    public Result queryTaskList(@CurrentUser JkdsUser loginUser, String id){
        QueryWrapper<JkdsClockConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(JkdsClockConfig.ColumnEnum.id.name(), id);
        return Result.success("查询成功",jkdsClockConfigService.getOne(queryWrapper));
    }
}

